Skip to main content

Setting user defaults

Setting user defaults in a Linux system involves configuring default settings and behaviors for user accounts. These defaults are applied when new user accounts are created or when existing users log in for the first time. To set user defaults, you can use various configuration files and commands.

  1. Useradd Defaults:

    • The useradd command allows you to specify default settings for newly created user accounts. You can configure these defaults in the /etc/default/useradd file.

    • Open the /etc/default/useradd file for editing:

      sudo nano /etc/default/useradd
    • Here are some common defaults that you can configure in this file:

      • HOME: Default home directory for new users.
      • CREATE_MAIL_SPOOL: Whether to create a mailbox for new users.
      • SHELL: Default shell for new users.
    • Save any changes you make and exit the text editor.

  2. Skeleton Directory:

    • The /etc/skel directory contains files and directories that are copied to a new user's home directory when the user is created. You can customize the contents of this directory to set default files or configurations for new users.

    • For example, if you want to provide a default .bashrc file for new users, place it in the /etc/skel directory:

      sudo cp /path/to/default/.bashrc /etc/skel/
    • Ensure that the files you place in /etc/skel have appropriate permissions and ownership.

  3. Login Defaults - /etc/login.defs:

    • The /etc/login.defs file contains system-wide defaults for user login settings. It includes parameters like password expiration policies, password complexity requirements, and more.

    • You can edit this file to configure login-related defaults, but exercise caution as some changes can affect the system's security policies.

    • Open the /etc/login.defs file for editing:

      sudo nano /etc/login.defs
    • Make changes as needed and save the file.

  4. Default Groups:

    • You can assign new users to default groups by configuring the /etc/default/useradd file, as mentioned earlier. However, you can also set default groups for users in the /etc/group file.

    • For example, if you want all new users to be members of a group named users, you can add them to the users group in the /etc/group file.

  5. Default Shell:

    • You can set the default shell for all users in the /etc/default/useradd file, as mentioned earlier. Alternatively, you can modify the /etc/passwd file to change the default shell for specific users.

    • Use the chsh command to change the shell for a user:

      sudo chsh -s /bin/bash username

      Replace /bin/bash with the desired shell and username with the username of the user you want to modify.

  6. Default umask:

    • The default umask value determines the permissions assigned to new files and directories created by users. You can set the default umask in the shell startup files, such as /etc/profile or /etc/bashrc.

    • For example, to set a default umask of 002 (which grants read, write, and execute permissions to the owner and group and read and execute permissions to others), you can add the following line to /etc/profile:

      umask 002
    • Make sure to add this line to the appropriate shell startup file depending on the default shell used in your system.